<?php
use Workerman\Worker;
use Workerman\Protocols\Http;
use WebWorker\Libs\Mredis;
use WebWorker\Libs\Mdb;
use WebWorker\Libs\Mmysqli;
//加载composer
require_once __DIR__.'/../../vendor/autoload.php';
//加载配置文件
require_once __DIR__ . '/../../config/config_production.php';
//加载错误码字典
require_once __DIR__ . '/../../config/errorcode.php';
//加载基础模型类
include_once __DIR__.'/models/Base_model.php';
//加载辅助类-validTools
include_once __DIR__.'/../../core/ValidTools.php';
 

$app = new WebWorker\App("http://0.0.0.0:1215");

$app->errorCode = $errorCode;

$app->name = "Demo1";

$app->count = 1;

$app->autoload = array(__DIR__."/../../core/",__DIR__."/controllers/",__DIR__."/libs/",__DIR__."/funcs/",__DIR__."/models/");

//设置监控
//$app->statistic_server = "udp://127.0.0.1:55656";

//初始化redis和mysqli连接
$app->onAppStart = function($app) use($config){

Logger::configure(__DIR__.'/../../config/config.xml');
$app->logger = Logger::getLogger('myLogger');

ValidTools::configure(__DIR__.'/../../config/API_Valid.xml');
$app->valid = ValidTools::getInstance();

$app->db = new Workerman\MySQL\Connection($config['db']['host'], $config['db']['port'], $config['db']['user'], $config['db']['password'], $config['db']['db']);

$app->redis = Mredis::getInstance($config["redis"]);

//支持接受reload信号，这包含的文件修改不需要重启 
WebWorker\autoload_dir($app->autoload); 
};

// 如果不是在根目录启动，则运行runAll方法
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}
